package cn.icanci.loopstack.bic.sdk.burying;

import java.io.Serializable;

import cn.icanci.loopstack.bic.sdk.burying.aop.ThreadLocalUtils;
import cn.icanci.loopstack.bic.sdk.properties.BicProperties;
import cn.icanci.loopstack.bic.sdk.system.LoggerLevelEnum;

/**
 * @author icanci
 * @since 1.0 Created in 2023/09/28 13:19
 */
public class BuryingBuilder implements Serializable {
    private static BicProperties bicProperties;

    public static void setBicProperties(BicProperties bicProperties) {
        BuryingBuilder.bicProperties = bicProperties;
    }

    public static BuryingDTO debug(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
        return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.DEBUG);
    }

    public static BuryingDTO info(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
        return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.INFO);
    }

    public static BuryingDTO warning(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
        return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.WARNING);
    }

    public static BuryingDTO error(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
        return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.ERROR);
    }

    private static BuryingDTO common(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message,
                                     LoggerLevelEnum loggerLevel) {

        String useCase = ThreadLocalUtils.getUseCase();
        String uk = ThreadLocalUtils.getUk();

        BuryingDTO burying = new BuryingDTO();
        burying.setSystemKey(bicProperties.getSystemKey());
        burying.setTraceId(traceId);
        burying.setBusinessNo(businessNo);
        burying.setUseCase(useCase);
        burying.setModule(module);
        burying.setCategory(category);
        burying.setSubCategory(subCategory);
        burying.setExt(ext);
        burying.setTime(System.currentTimeMillis());
        burying.setMessage(message);
        burying.setLoggerLevel(loggerLevel.name());
        burying.setUniqueKey(uk);
        return burying;
    }
}
